<template>
	<view class="index">
		<mescroll-uni height="100%" @init="mescrollInit" @down="refresh" :up="upOption" :down="downOption">
			<view class="bg">

			</view>
			<view class="top-title-wrapper"
				:style="{'margin-top': menuButtonInfo.top + 'px','height': menuButtonInfo.height + 'px'}">
				<text>好帮集配.城市仓</text>
				<text v-if="environment === 'D'">(测试环境)</text>
				<text v-else-if="environment === 'T'">(体验环境)</text>
			</view>
			<view class="top-wrapper">
				<view class="top-bg-wrapper">
				</view>
				<view class="top-content-wrapper">
					<view class="user-info" @click="goPage('/subPage_mine/index')">
						<view class="info-wrapper">
							<view class="nickname">
								<text>{{ userInfo.staffName }}</text>
								<uni-icons type="right" class="icon" size="12" color="#06093B"></uni-icons>
								<view v-if="userInfo.cityPointInfo && userInfo.cityPointInfo.pointStatus == 1"
									class="tag">
									接单中
								</view>
								<view v-if="userInfo.cityPointInfo && userInfo.cityPointInfo.pointStatus == 2"
									class="tag error">
									暂停接单
								</view>
							</view>
							<view class="store-name">
								{{ userInfo.cityPointInfo.belongCity }}.{{ userInfo.cityPointInfo.pointName }}
							</view>
						</view>
						<image class="logo" src="https://cdpresources.hobon.cc/city-warehouse-app/static/logo.png"
							mode="widthFix"></image>
					</view>
					<view class="schedule-wrapper">
						<view class="item" @click="goPage('/subPage_order/index','order:form')">
							<view class="number">{{ countStatistics.order || 0 }}</view>
							<view class="label">
								订货单
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_order/index?type=1','order:form')">
							<view class="number">{{ countStatistics.to_be_paid || 0 }}</view>
							<view class="label">
								待付款
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_transport/index','transportation:management')">
							<view class="number">{{ countStatistics.meet_car || 0 }}</view>
							<view class="label">
								待接车
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_pickup/index?type=2','bill:of:lading')">
							<view class="number">{{ countStatistics.waiting_for_pickup || 0 }}</view>
							<view class="label">
								待提货
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_pickup/index?type=3','bill:of:lading')">
							<view class="number">{{ countStatistics.waiting_for_delivery || 0 }}</view>
							<view class="label">
								待配送
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_pickup/outStock','bill:of:lading')">
							<view class="number">{{ countStatistics.refund || 0 }}</view>
							<view class="label">
								缺货退款
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_afterSale/index?type=1','refund:after:sale')">
							<view class="number">{{ countStatistics.after_sale || 0 }}</view>
							<view class="label">
								售后审核
							</view>
						</view>
					</view>
					<view class="notice-wrapper">
						<cc-noticeBar style="width: 100%;" colors="#575A6E" :noticeList="noticeList" @click="itemClick"
							@goMore="goMore"></cc-noticeBar>
					</view>
				</view>
			</view>

			<view class="content-wrapper">
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							销售
						</view>
					</view>
					<view class="item-wrapper">
						<view class="item" @click="goPage('/subPage_customer/index','customer:management')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/customer.png"
								class="icon" mode="widthFix"></image>
							<view class="label">
								客户管理
							</view>
						</view> <!-- @click="goPage('/subPage_product/productManagement')" -->
						<view class="item" @click="goPage('/subPage_order/index','order:form')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/order.png" class="icon"
								mode="widthFix"></image>
							<view class="label">
								订货单
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_product/index','product:selection')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/productManage.png"
								class="icon" mode="widthFix"></image>
							<view class="label">
								商品经营
							</view>
						</view>
						<!-- <view class="item">
						<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/coupon.png" class="icon"
							mode="widthFix"></image>
						<view class="label">
							优惠券
						</view>
					</view> -->
					</view>
				</view>
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							物流
						</view>
					</view>
					<view class="item-wrapper">
						<view class="item" @click="goPage('/subPage_transport/index','transportation:management')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/transport.png"
								class="icon" mode="widthFix"></image>
							<view class="label">
								运输管理
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_distribution/index','scan:code:divide:goods')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/scan.png" class="icon"
								mode="widthFix"></image>
							<view class="label">
								分货管理
							</view>
						</view>
						<view class="item" @click="pickup">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/customerPickUp.png"
								class="icon" mode="widthFix"></image>
							<view class="label">
								客户提货
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_pickup/index','bill:of:lading')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/pickUp.png" class="icon"
								mode="widthFix"></image>
							<view class="label">
								提货单
							</view>
						</view>
					</view>
				</view>
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							结算
						</view>
					</view>
					<view class="item-wrapper"> <!-- @click="goPage('/subPage_product/newProduct')" -->
						<!-- <view class="item" @click="goPage('/subPage_payInfo/index','receivables:account')">
						<image src="https://cdpresources.hobon.cc/supplier-mini-program/static/account-number.png"
							class="icon" mode="widthFix"></image>
						<view class="label">
							收款账号
						</view>
					</view> -->
						<view class="item" @click="goPage('/subPage_fund/index','fund:settlement')">
							<image src="https://cdpresources.hobon.cc/supplier-mini-program/static/settlement.png"
								class="icon" mode="widthFix"></image>
							<view class="label">
								资金结算
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_afterSale/index','refund:after:sale')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/refund.png" class="icon"
								mode="widthFix"></image>
							<view class="label">
								售后退款
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_fine/index','fine:management')">
							<image src="https://cdpresources.hobon.cc/supplier-mini-program/static/fine.jpg"
								class="icon" mode="widthFix"></image>
							<view class="label">
								违约扣款
							</view>
						</view>
					</view>
				</view>
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							管理
						</view>
					</view>
					<view class="item-wrapper">
						<view class="item" @click="goPage('/subPage_staff/index','account:authority')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/staff.png" class="icon"
								mode="widthFix"></image>
							<view class="label">
								员工管理
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_report/index','operating:statement')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/report.png" class="icon"
								mode="widthFix"></image>
							<view class="label">
								经营报表
							</view>
						</view>
						<!-- <view class="item" @click="goPage('/subPage_bluetooth/print')">
						<image src="https://cdpresources.hobon.cc/supplier-mini-program/static/bluetooth.png"
							class="icon" mode="widthFix"></image>
						<view class="label">
							蓝牙连接
						</view>
					</view> -->
						<!-- <view class="item">
						<image src="../../static/logo.png" class="icon" mode="widthFix"></image>
						<view class="label">
							使用教程
						</view>
					</view> -->
					</view>
				</view>
			</view>
			<view class="block">

			</view>

			<uni-popup ref="popup">
				<view class="popup-wrapper">
					<view class="title-wrapper">
						客户提货
					</view>
					<view class="form-item">
						<!-- <view class="label">
						提货码：
					</view> -->
						<view class="input-wrapper">
							<input type="text" auto-focus v-model="customerName" placeholder="请输入客户名称" class="input">
						</view>
					</view>
					<view class="popup-btn-wrapper">
						<view class="btn cancel" @click="scan">
							<uni-icons type="scan" size="20" color="#F26022"></uni-icons>
							<text>扫码提货</text>
						</view>
						<view class="btn" @click="query">
							查询提货
						</view>
					</view>
				</view>
			</uni-popup>
		</mescroll-uni>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				downOption: {
					auto: true, // 不自动加载 (mixin已处理第一个tab触发downCallback)
					textColor: "#ffffff"
				},
				upOption: {
					use: false,
					isLock: true
				},
				environment: uni.getStorageSync('environment'),
				noticeList: [],
				menuButtonInfo: {},
				customerName: '',
				countStatistics: {}
			}
		},
		onLoad() {
			this.init()
		},
		onShow() {
			this.getCount()
		},
		onShareAppMessage() {

		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			},
			bankInfo() {
				return this.$store.state.bankInfo
			},
		},
		methods: {
			init() {
				this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				this.getNotice();
			},
			async getNotice() {
				const data = await this.$api.post('/app/notice/page', {
					noticeType: 2,
					pageNum: 1,
					pageSize: 10,
					orders: [{
						"asc": false,
						"column": "noticeId"
					}],
				})
				if (data.code === 200) {
					this.noticeList = data.data.records.map(item => {
						return {
							id: item.noticeId,
							title: item.noticeTitle
						}
					});
				}
			},
			async getCount() {
				const data = await this.$api.get('/app/pickuppoint/todoCount', {
					pickupPointId: this.userInfo.pickupPointId
				}, false)
				if (data.code === 200) {
					this.countStatistics = data.data;
				}
			},
			refresh() {
				this.getCount()
				this.mescroll.endSuccess(1, false)
			},

			goPage(url, code) {
				if (code && !this.$permissions.verify(code)) {
					uni.showModal({
						title: '提示',
						content: '您没有权限访问',
						showCancel: false,
						confirmText: '确定'
					})
					return
				}
				if (code === 'fund:settlement' && !this.bankInfo) {
					uni.showModal({
						title: '提示',
						content: '您暂未开通结算账户，请联系平台开通~',
						showCancel: false,
						confirmText: '确定'
					})
					return
				}
				uni.navigateTo({
					url: url
				})
			},
			pickup() {
				if (!this.$permissions.verify('customer:pick-up')) {
					uni.showModal({
						title: '提示',
						content: '您没有权限访问',
						showCancel: false,
						confirmText: '确定'
					})
					return
				}
				this.customerName = '';
				this.$refs.popup.open('center')
			},
			itemClick(e) {
				this.goPage('/subPage_notice/detail?id=' + e.id)
			},
			goMore() {
				this.goPage('/subPage_notice/index')
			},
			scan() {
				this.$refs.popup.close()
				uni.scanCode({
					scanType: ["qrCode"],
					success: async (res) => {
						if (res.result.indexOf('hobon_') > -1) {
							uni.navigateTo({
								url: '/subPage_pickup/list?customerId=' + res.result.split('_')[1]
							})
						} else {
							uni.showToast({
								title: '无效的二维码',
								icon: 'error'
							})
						}
					}
				});
			},
			query() {
				if (!this.customerName) {
					uni.showToast({
						title: '请输入客户名称',
						icon: 'error'
					})
					return
				}
				uni.navigateTo({
					url: '/subPage_pickup/list?customerName=' +
						this.customerName
				})
				this.$refs.popup.close()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;
		position: relative;

		.block {
			height: 100rpx;
		}

		.bg {
			width: 100%;
			height: 508upx;
			background: url('https://cdpresources.hobon.cc/city-warehouse-app/static/index-bg.png') no-repeat;
			background-size: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.top-title-wrapper {
			padding: 0 42upx;
			position: relative;
			display: flex;
			align-items: center;
			font-size: 42upx;
			font-weight: bold;
			color: #fff;
		}

		.top-wrapper {
			padding: 0 42upx;
			height: 575rpx;
			position: relative;
			margin-top: 40upx;

			.top-bg-wrapper {
				position: absolute;
				left: -10rpx;
				top: 0;
				width: 675rpx;
				height: 55%;
				background-color: rgba(255, 255, 255, .2);
				border-radius: 28upx;
				transform: rotate(-4deg);
				z-index: 0;
			}

			.top-content-wrapper {
				position: relative;
				z-index: 1;
				width: 100%;
				height: 100%;
				border-radius: 28upx;
				background-color: #ffffff;
				box-shadow: 0px 9rpx 14rpx rgba(186, 121, 99, 0.3);
				overflow: hidden;
			}

			.user-info {
				display: flex;
				align-items: center;
				padding: 0 20upx 0 40rpx;
				margin-top: 20upx;
				color: #06093B;
				position: relative;
				z-index: 1;

				.logo {
					width: 170upx;
					height: 170upx;
					margin-left: 20upx;
				}

				.info-wrapper {
					flex: 1;

					.nickname {
						font-size: 40upx;
						display: flex;
						align-items: center;

						.icon {
							margin: 0 15upx 0 5upx;
							line-height: 12rpx;
						}

						.tag {
							min-width: 100upx;
							height: 42upx;
							font-size: 24upx;
							background-color: #EDF7EB;
							color: #1DB000;
							border-radius: 10upx;
							display: flex;
							align-items: center;
							justify-content: center;
							padding: 0 15upx;

							&.error {
								color: #FF4403;
								background-color: #FFECDB;
							}
						}
					}

					.store-name {
						font-size: 32upx;
						margin-top: 14upx;
						color: #505157;
					}
				}
			}

			.schedule-wrapper {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				margin-top: 20upx;

				.item {
					width: 25%;
					text-align: center;

					.number {
						color: red;
						font-size: 46upx;
						font-weight: bold;
						margin-bottom: 10upx;
					}

					.label {
						font-size: 28upx;
						color: #575A6E;
						margin-bottom: 40upx;
					}
				}
			}

			.notice-wrapper {
				position: absolute;
				width: 100%;
				bottom: 0;
				padding: 0 20upx;
				height: 80upx;
				background-color: #FAEDEB;
				display: flex;
				align-items: center;
				color: #000000;
				z-index: 1;
				box-sizing: border-box;

				.icon {
					margin-right: 20upx;
				}

				.notice-content {
					font-size: 28upx;
					flex: 1;
				}
			}
		}

		.content-wrapper {
			padding: 0 42upx;
			position: relative;
		}

		.function-wrapper {
			background-color: #ffffff;
			box-shadow: 0 0 10rpx #efefef;
			border-radius: 20upx;
			margin: 28upx 0;
			overflow: hidden;

			.title-wrapper {
				display: flex;
				align-items: center;
				padding: 0 20upx;
				margin: 35rpx 0;

				.title {
					height: 36upx;
					line-height: 36upx;
					font-size: 36upx;
					color: #000000;
					padding-left: 15upx;
					//border-left: 10upx solid #018737;
				}
			}

			.item-wrapper {
				display: flex;
				align-items: center;
				flex-wrap: wrap;

				.item {
					width: 25%;
					text-align: center;

					.number {
						color: red;
						font-size: 32upx;
						font-weight: bold;
						margin-bottom: 15upx;
					}

					.label {
						font-size: 28upx;
						color: #575A6E;
						margin-bottom: 40upx;
						//margin: 15upx 0;
					}

					.icon {
						width: 70upx;
						height: 70upx;
						border-radius: 24;
						margin-bottom: 10upx;
					}
				}
			}
		}

		.time-info {
			margin-top: 25upx;
			color: #000000;
			padding: 26upx 0;

			.title {
				position: relative;
				font-size: 32upx;
				font-weight: bold;
				margin-bottom: 30upx;
				display: inline-block;
				color: #212121;

				.line {
					position: absolute;
					height: 16rpx;
					width: 100%;
					background-color: #A9D9F5;
					bottom: 2rpx;
					left: -5rpx;
					border-radius: 15rpx;
				}

				.text {
					position: relative;
					z-index: 1;
				}
			}



			.info {
				font-size: 26upx;
				margin-bottom: 10upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #575A6E;
			}
		}

		.sjx-logo {
			width: 90%;
			margin-left: 5%;
			margin-bottom: -100upx;
		}


		.popup-wrapper {
			width: 600upx;
			background-color: #ffffff;
			border-radius: 20upx;
			min-height: 300upx;
			overflow: hidden;

			.title-wrapper {
				height: 100upx;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 32upx;
				font-size: 36upx;
				color: #2B2B2B;
			}

			.form-item {
				margin: 0 44upx;
				height: 100upx;
				display: flex;
				align-items: center;
				border-bottom: 2upx solid #f9f9f9;

				.label {
					font-size: 32upx;
					color: #5B5B5B;
				}

				.input-wrapper {
					height: 70upx;
					flex: 1;
					border: 1upx solid #dedede;
					border-radius: 10upx;
					margin-right: 15upx;

					.input {
						height: 70upx;
						width: 100%;
						text-align: center;
					}
				}
			}

			.popup-btn-wrapper {
				height: 150upx;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 40upx;

				.btn {
					width: 260upx;
					height: 76upx;
					border-radius: 40upx;
					background-color: #F26022;
					color: #ffffff;
					display: flex;
					align-items: center;
					justify-content: center;
					transition: .15s linear;

					&:active {
						background-color: #F2602266;
					}

					&.cancel {
						box-sizing: border-box;
						background-color: #ffffff;
						border: 2upx solid #F26022;
						margin-right: 40upx;
						color: #F26022;

						&:active {
							background-color: #F2F4FA77;
						}
					}
				}
			}
		}
	}
</style>